import {
    observable,
    computed,
    action,
    makeObservable
} from 'mobx'
import axios from "axios";
import qs from "qs";
// import api from '../api/index'
// import qs from 'qs'
class User {
    constructor() {
        makeObservable(this)

    }
    user;
    token;
    gongnengInfo
    @observable isLogin = false;
    @computed get user() {
        if (sessionStorage.getItem('user')) {
            return JSON.parse(sessionStorage.getItem('user'))
        }
        return {}
    }
    set user(data) {
        sessionStorage.setItem('user', JSON.stringify(data))
    }
    @computed
    set gongnengInfo(data) {
        sessionStorage.setItem('gongnengInfo', JSON.stringify(data))
    }
    get gongnengInfo() {
        if (sessionStorage.getItem('gongnengInfo')) {
            return JSON.parse(sessionStorage.getItem('gongnengInfo'))
        }
        return {}
    }
    @computed get token() {
        if (sessionStorage.setItem('token')) {
            return sessionStorage.getItem('token')
        }
        return "";
    }
    set token(value) {
        sessionStorage.setItem('token', JSON.stringify(value));
    }

    @action
    Login(user, menus, token) {
        this.isLogin = true;
        this.user = user;
        this.gongnengInfo = menus
        this.token = token;
    }
    @action
    upLogin(user, pwd) {
        this.isLogin = false;
        this.user = user;
        this.pwd = pwd
    }
    // @action
    // userLogin(userInfo){  //userInfo,用户名，密码，记住密码
    //     // 进行异步请求
    //     console.log("store",userInfo);
    //     return new Promise(((resolve, reject) => {
    //         axios.post(api.user.UserLogin,qs.stringify(userInfo)).then((res)=>{
    //             if(res.data.returnCode==200){
    //                 this.user = res.data.data;
    //                 this.token = res.data.token;
    //                 resolve(res.data);
    //             }else{
    //                 reject(res.data);
    //             }
    //         })
    //     }));
    // }
}
const login = new User()
export default login